package models

import (
	"gorm.io/gorm"
	"time"
	"user_srv/basic/config"
)

type Car struct {
	Id            uint           `gorm:"column:id;type:bigint(20) UNSIGNED;primaryKey;not null;" json:"id"`
	DriverId      uint           `gorm:"column:driver_id;type:bigint(20);comment:司机ID;not null;" json:"driver_id"`           // 司机ID
	LicenseNumber string         `gorm:"column:license_number;type:varchar(50);comment:车牌号;not null;" json:"license_number"` // 车牌号
	Brand         string         `gorm:"column:brand;type:varchar(50);comment:车辆品牌;not null;" json:"brand"`                  // 车辆品牌
	Model         string         `gorm:"column:model;type:varchar(50);comment:车型;not null;" json:"model"`                    // 车型
	Color         string         `gorm:"column:color;type:varchar(50);comment:颜色;not null;" json:"color"`                    // 颜色
	Seat          uint           `gorm:"column:seat;type:int(10);comment:座位号;not null;" json:"seat"`                         // 座位号
	CarsUrl       string         `gorm:"column:cars_url;type:varchar(255);comment:车辆图片;not null;" json:"cars_url"`           // 车辆图片
	CreatedAt     time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt     time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt     gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (c *Car) TableName() string {
	return "car"
}
func (c *Car) BrandDirverCar() error { //绑定车辆
	return config.DB.Create(&c).Error
}
func (c *Car) CartType() (carLists []*Car, err error) {
	err = config.DB.Where("model like ?", "%"+c.Model+"%").Find(&carLists).Error
	return
}
